<template>
  <h3>{{ pList.title }}</h3>
  <div id="section">
    <bTableVue :instance="pList"></bTableVue>
    <ElDialog v-model="dForm._show" :title="dForm.title" destroy-on-close :close-on-click-modal="false">
      <bForm :instance="dForm" cover="50%">
        <el-button @click="onUpdate">完成</el-button>
      </bForm>
    </ElDialog>
  </div>
</template>
<script setup lang="ts">
import { Rolelist, Rolefrom } from "@b/index/role";
import bTableVue from "@/components/public/b_table.vue";
import bForm from "@/components/public/b_form.vue";
import { ElDialog, ElButton } from "element-plus";

const pList = new Rolelist();
const dForm = new Rolefrom();

const onUpdate = async () => {
  const res = await dForm.updateData();
  if (res) {
    dForm._show = false;
    pList.refresh();
    pList.recache();
  }
};
pList.add = () => {
  dForm._show = true;
  dForm.title = "添加身份";
  dForm.id = undefined;
};
pList.edit = async (id) => {
  if (!id) return;
  dForm._show = true;
  dForm.id = id;
  dForm.title = "修改身份信息";
  await dForm.setData();
};
</script>
<style scoped></style>
